import { notification } from 'antd';

interface error {
  name: string;
  data: any;
  type: string;
  response: {
    status: number;
    statusText: string;
    url: string;
  };
}

/**
 * 异常处理程序
 */
const errorHandler = (error: error) => {
  if (error.name === 'BizError') {
    notification.destroy();
    notification.error({
      message: error.data.msg,
    });
    return error.data.code;
  }
  if (error.name === 'ResponseError') {
    notification.destroy();
    notification.error({
      message: error.data.msg,
    });
    return error.data.code;
  }
  const { response } = error;
  notification.destroy();
  notification.error({
    message: response,
  });
  return error.data.code;
};
export default errorHandler;
